//
//  IMMessage.m
//  IMChezhil
//
//  Created by zhangliucheng on 15/7/3.
//  Copyright (c) 2015年 CheZhil. All rights reserved.
//

#import "IMTextMessage.h"
#import "IMTool.h"

@implementation IMTextMessage

- (instancetype)initWithContent:(NSString *)content {
    self = [super initWithMessageId:[IMTool productMessageId] messageType:MessageTypeText messageDirection:MessageOwnerSend];
    if (self) {
        self.content = content;
    }
    return self;
}

- (instancetype)initWithMessageId:(NSString *)msgId content:(NSString *)content {
    self = [super initWithMessageId:msgId messageType:MessageTypeText messageDirection:MessageOwnerReceive];
    if (self) {
        self.content = content;
    }
    return self;
}

- (NSData *)sendData {
    NSMutableDictionary *dict = [NSMutableDictionary new];
    [dict setObject:self.messageId forKey:@"id"];
    [dict setObject:self.content forKey:@"messageContent"];
    NSData *contentData = [NSJSONSerialization dataWithJSONObject:dict options:NSJSONWritingPrettyPrinted error:Nil];
    NSString *content = [[NSString alloc] initWithData:contentData encoding:NSUTF8StringEncoding];
    return [IMTool sendDataWithCode:CMD_USER_CHAT_MSG content:content];
}

@end
